Skip to main content

Untyped lambda calculus

Notes taken from Type Theory and Formal proof. An introduction

Construction principles

  1. Abstraction: λx.M.\lambda x.M. (read as abstraction of M over x)
  2. Application MNM N (read as application of M to N).

If it is necessary, some parentheses should be added during the construction process. e.g

Abstraction of yy over λ.xy\lambda. x - y

λy.(λx.xy)\lambda y.(\lambda x. x - y)

Functions of more than one argument: Currying

The function f(x,y)=x2+yf(x, y) = x^2 + y can be write as λx.(λy.(x2+y))\lambda x. (\lambda y. (x^2 + y)).

Lambda terms

Expressions in the lambda calculus are called λterm\lambda-term. Λ\Lambda is the set of all λterms\lambda-terms. To start with, we assume the existence of an infinite set VV of so-called variables: V={x,y,z,..}V = \{x, y, z, ..\}

  1. Variable: if uVu \in V, then uΛu \in \Lambda
  2. Application: if MM and NΛN \in \Lambda, then (MN)Λ(M N) \in \Lambda
  3. Abstraction if uVu \in V and MΛM \in \Lambda, then (λu.M)Λ(\lambda u. M) \in \Lambda

so, Λ=V(ΛΛ)(λV.Λ)\Lambda = V|(\Lambda \Lambda)|(\lambda V. \Lambda)

Subterms

All λterm\lambda-term has sub terms defined as:

  1. Basis: Sub(x)={x}Sub(x) = \{x\}, for each xVx \in V
  2. Application: Sub((MN))=Sub(M)Sub(N){(MN)}Sub((M N)) = Sub(M) \cup Sub(N) \cup \{(M N)\}
  3. Abstraction: Sub((λx.M))=Sub(M){(λx.M)}Sub((\lambda x.M)) = Sub(M) \cup \{(\lambda x.M)\}

Subterm properties

  1. Reflexivity: For all λterms M\lambda-terms\ M, we have MSub(M)M \in Sub(M)
  2. Transitivity: If LSub(M)L \in Sub(M) and MSub(N)M \in Sub(N), then LSub(N)L \in Sub(N)

Proper subterm

LL is a proper subterm of MM if LL is a subterm of MM, but L≢ML \not \equiv M

Free and bound variables

  1. binding variable: variable after λ\lambda e.g. λx.\lambda x.
  2. bound variable: If a binding variable is used in the expression it is bound in the expression

Free variables definition

FVFV is the set of free variables of a λterm\lambda-term

  1. Variable: FV(x)={x}FV(x) = \{x\}
  2. Application: FV(MN)=FV(M)FV(N)FV(MN) = FV(M) \cup FV(N)
  3. Abstraction: FV(λx.M)=FV(M){x}FV(\lambda x. M) = FV(M) \setminus \{x\}

Closed λterm\lambda-term

The λterm\lambda-term MM is closed if FV(M)=FV(M) = \emptyset. A closed λterm\lambda-term is also called a combinator. The set of all closed λterms\lambda-terms is denoted by λ0\lambda^0

αconversion\alpha-conversion

It is the possibility of renaming binding (and bound) variables.

Let MxyM^{x \to y} denote the result of replacing every free occurrence of xx in MM by yy. defined as: λx.M=αλy.Mxy\lambda x. M =_\alpha \lambda y. M^{x \to y}, provided that yFV(M)y \notin FV(M) and yy is not a binding variable in MM

Properties

  1. Compatibility: if M=αNM =_\alpha N, then ML=αNLML =_\alpha NL, LM=αLNLM =_\alpha LN and, for arbitrary zz, λz.M=αλz.N\lambda z. M =_\alpha \lambda z. N
  2. Reflexivity: M=αMM =_\alpha M
  3. Symmetry: If M=αNM =_\alpha N then N=αMN =_\alpha M
  4. Transitivity: If both L=αML =_\alpha M and M=αNM =_\alpha N, then L=αNL =_\alpha N

αvariant\alpha-variant

If M=αNM =_\alpha N, then MM and NN are said to be αconvertible\alpha-convertible or αequivalent\alpha-equivalent. MM is called an αvariant\alpha-variant of NN (and vice versa)

Function evaluation process βreduction\beta-reduction

An expression of the form (λx.M)N(\lambda x. M)N can be rewritten to the expression M[x:=N]M[x:=N], i.e. the expressions MM in which every xx has been replaced with NN. We call this process βreduction\beta-reduction of (λx.M)N(\lambda x. M)N to M[x:=N]M[x:=N]. e.g

  1. (λx.x2+1)(3)(\lambda x. x^2 + 1)(3) reduces to (x2+1)[x:=3](x^2 + 1)[x := 3] which is 32+13^2 + 1.
  2. (λz.(λx.x)(λy.y))(\lambda z. (\lambda x. x)(\lambda y.y)) reduces to (λz.(λy.y))(\lambda z. (\lambda y. y))
note

Application is the construction of new expression, not the execution of the expression. It is only after the reduction of the latter term that we obtain the result of the application

Substitution

  1. x[x:=N]Nx[x:=N] \equiv N
  2. y[x:=N]yy[x:=N] \equiv y if x≢yx \not\equiv y
  3. (PQ)[x:=N]P[x:=N] Q[x:=N](PQ)[x := N] \equiv P[x := N]\ Q[x := N]
  4. (λy.P)[x:=N]λz.(Pyz[x:=N])(\lambda y. P)[x := N] \equiv \lambda z. (P^{y \to z}[x := N]), if λz.Pyz\lambda z. P^{y \to z} is an αvariant\alpha-variant of λy.P\lambda y. P such that zFV(N)z \notin FV(N)

One step β\beta-reduction β\to_\beta

The incentive to defining the relation β\to_\beta is the presence of an application term where the first part is an abstraction: λx.M\lambda x. M. Since an abstraction can be thought of as representing a function, we can conceive of part NN as an argument for this function.

  1. Basis: (λx.M)NβM[x:=N](\lambda x. M)N \to_\beta M[x:=N]
    1. The subterm of the form (λx.M)N(\lambda x. M)N on the left hand side is called a redex (from reducible expression). The subterm M[x:=N]M[x:=N] on the right hand side is called the contractum (of the redex)
  2. Compatibility: (MβN)(M \to_\beta N), then MLβNLML \to_\beta NL, LMβLNLM \to_\beta LN and λx.Mβλx.N\lambda x. M \to_\beta \lambda x. N

Zero or more steps β\beta-reduction β\twoheadrightarrow_\beta

MβNM \twoheadrightarrow_\beta N if there is n0n \ge 0 and there are terms M0M_0 to MnM_n such that M0MM_0 \equiv M, MnNM_n \equiv N and for all ii such that 0i<n0 \le i \lt n: MiβMi+1M_i \to_\beta M_{i+1}

Hence, if MβNM \twoheadrightarrow_\beta N, there exists a chain of single-step β\beta-reductions, starting with MM and ending with NN:

MM0βM1βM2ββMn2βMn1βMnNM \equiv M_0 \to_\beta M_1 \to_\beta M_2 \to_\beta \dots \to_\beta M_{n-2} \to_\beta M_{n-1} \to_\beta M_{n} \equiv N

Lemma:

  1. β\twoheadrightarrow_\beta extends β\to_\beta, i.e. if MβNM \to_\beta N, then MβNM \twoheadrightarrow_\beta N.
  2. β\twoheadrightarrow_\beta is reflesive and transitive, i.e:
    1. (refl): for all M:MβMM: M \twoheadrightarrow_\beta M,
    2. (trans): for all LL, MM and NN: if LβML \twoheadrightarrow_\beta M and MβNM \twoheadrightarrow_\beta N then LβNL \twoheadrightarrow_\beta N.

β\beta-conversion, β\beta-equality, =β=_\beta

M=βNM =_\beta N if there is an n0n \ge 0 and there are terms M0M_0 to MnM_n such that M0M,MnNM_0 \equiv M, M_n \equiv N and for all ii such that 0i<n0 \le i \lt n: either MiβMi+1M_i \to_\beta M_{i+1} or Mi+1βMiM_{i+1} \to_\beta M_i

For example: (λy.yv)z=β(λx.zx)v(\lambda y. yv)z =_\beta (\lambda x. zx)v since we have the following chain, where β\leftarrow_\beta is the inverse of β\to_\beta:

(λy.yv)zβzvβ(λx.zx)v (\lambda y. yv)z \to_\beta zv \leftarrow_\beta (\lambda x. zx)v

=β=_\beta is an equivalence relation, hence reflexive, symmetric and transitive

β\beta-normal form (β\beta-nf)

  1. MM is in β\beta-normal form if MM does not contain any redex
  2. MM has a β\beta-normal form if there is an NN in β\beta-normal form that M=βNM =_\beta N. Such an N is a β\beta-normal form of MM

When MM is in β\beta-nf, then MβNM \twoheadrightarrow_\beta N implies MNM \equiv N

Fixed point theorem

For all LΛL \in \Lambda there is MΛM \in \Lambda such that LM=βMLM =_\beta M. e.g the function f(n)=n2f(n) = n^2, has two fixed points 00 and 11. The successor function s(n)=n+1s(n) = n + 1 has no fixed point at all.